package bag;

import java.util.LinkedList;
import java.util.Queue;

/**
 * Creared with IntelliJ IDEA.
 * Description:
 * User:yxd
 * Date:2022-01-29
 * Time:20:39
 */
class MyCircularQueue {//循环队列
    public int[] elem;
    public int front;//队头
    public int rear;//队尾

    public MyCircularQueue(int k) {
        elem = new int[k + 1];//会浪费一个元素 所以要多一个元素
    }
    public boolean enQueue(int value) {
        if(isFull())return false;
        elem[rear] = value;
        //rear++
        rear = (rear + 1) % elem.length;
        return true;
    }

    public boolean deQueue() {
        if(isEmpty())return false;
        //floan ++
        front = (front + 1) % elem.length;
        return true;
    }
    public int Front() {
        if(isEmpty()) return -1;
        return elem[front];//当前队头
    }
    public int Rear() {
        if(isEmpty()) return -1;
        //队尾 的前一个
        int a = -1;
        if(rear == 0){//队尾为0 则要重新赋值
            a = elem.length - 1;
        }else{
            a = rear -1;
        }
        return elem[a];
    }
    public boolean isEmpty() {
        return rear == front;
    }
    public boolean isFull() {
        if((rear + 1) % elem.length == front){//队尾的下一个元素为队头
            return true;
        }
        return false;
    }
}
public class MyQueue {
    public static void main(String[] args) {
        Queue<Integer> queue = new LinkedList<>();
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        queue.offer(4);
        queue.offer(5);
        queue.poll();
        queue.peek();
        queue.isEmpty();

    }
}
